package cn.edu.scau.cmi.wuzhenzhou.client;

import java.io.InputStream;
import java.util.Scanner;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.wuzhenzhou.service.StudentService;
import cn.edu.scau.cmi.wuzhenzhou.service.TeacherService;
import cn.edu.scau.cmi.wuzhenzhou.util.ApplicationContextUtil;

public class ComprehensionClient {
	public static void cover() {
		System.out.println("1.添加学生\n" +
				   "2.修改学生\n" +
				   "3.删除学生\n" +
				   "4.添加教师\n" +
				   "5.修改教师\n" +
				   "6.删除教师\n" +
				   "7.学生选择指导老师\n" +
				   "8.学生修改指导老师\n" +
				   "9.教师选择被指导的学生\n" +
				   "10.教师修改被指导的学生  0.退出\n"+"请输入选择:");
	}
	
	public void start() throws Exception{
		ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
		StudentService stService = ac.getBean("studentService",StudentService.class);
		TeacherService tService = ac.getBean("teacherService",TeacherService.class);
		Scanner in = new Scanner(System.in);
		while(true) {
			cover();
			switch(in.nextInt()) {
			case 1:
				stService.addStudent();
				break;
			case 2:
				stService.updateStudent();
				break;
			case 3:
				stService.deleteStudent();
				break;
			case 4:
				tService.addTeacher();
				break;
			case 5:
				tService.updateTeacher();
				break;
			case 6:
				tService.deleteTeacher();
				break;
			case 7:
			case 8:
				stService.updateTeacherOfStudent();
				break;
			case 9:
				tService.addStudentOfTeacher();
				break;
			case 10:
				tService.updateTeacherOfStudent();
				break;
			case 0:
				return;
			default:
				System.out.println("输入错误");
				break;
			}
		}
	}
}
